package edu.spbsu.nonsm00th.qdiff.parser.word;

/**
 * Enum of all possible functions.
 * TODO: possible to add arcsh, arcch, arcth, arccth
 *
 * @author mbuzdov
 */
public enum Function implements Word {//TODO: maybe impl with Enum.name?

    /* trigonometric */
    SIN("sin", 1),
    COS("cos", 1),
    TG("tg", 1),
    CTG("ctg", 1),
    ARCSIN("arcsin", 1),
    ARCCOS("arccos", 1),
    ARCTG("arctg", 1),
    ARCCTG("arcctg", 1),
    /* exponential and logarithmic */
    EXP("exp", 1),
    LN("ln", 1),

    POWER("power", 2),
    LOG("log", 2),

    SH("sh", 1),
    CH("ch", 1),
    TH("th", 1),
    CTH("cth", 1),
    /* max, min*/
    MAX("max"),
    MIN("min");

    public static String ALPHABET = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    public static String VARIANTS;
    static {
        StringBuilder builder = new StringBuilder();
        Function[] functions = Function.values();
        for (int i = 0; i < functions.length; i++) {
            builder.append(functions[i].value);
            if (i + 1 < functions.length) {
                builder.append(", ");
            }
        }
        VARIANTS = builder.toString();
    }

    private String value;

    private Function(String value) {
        this.value = value;
    }

    @Deprecated
    private Function(String value, int argumentsCount) {
        this.value = value;
    }

    public static Function getFunction(String value) {
        for (Function function : values()) {
            if (function.value.equals(value)) {
                return function;
            }
        }
        return null;
    }
}
